package com.itheima.mall.entity.page;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MyPage<T> implements Serializable {

    private static final long serialVersionUID =  3877748210909763748L;

    private Long total; //总条数
    private Long totalPage; //总页数
    private Long pageNum; //当前页数
    private Long pageSize; //每页展示条数
    private List<T> list;

    public static <T>MyPage<T> init(Page page){
        //将查询到的数据封装给mypage
        MyPage<T> myPage = new MyPage<>();
        myPage.setTotal(page.getTotal());
        myPage.setTotalPage(page.getPages());
        myPage.setPageNum(page.getCurrent());
        myPage.setPageSize(page.getSize());
        myPage.setList(page.getRecords());
        return myPage;

    }
}
